package com.gun3y.utils;

import java.io.File;
import java.io.IOException;
import java.util.Properties;

import org.apache.commons.io.FileUtils;
import org.springframework.stereotype.Component;

@Component
public class ResourceLoader {

    private Properties tagProperties = new Properties();
    private Properties swProperties = new Properties();
    private String reasoningRules;

    private final String PROP_TAG_FILENAME = "html-tags.properties";

    private final String PROP_SW_FILENAME = "sw.properties";

    private final String PROP_REASONER_RULES = "reasoner.rules";

    public ResourceLoader() {
	try {
	    this.tagProperties.load(this.getClass().getClassLoader().getResourceAsStream(PROP_TAG_FILENAME));
	    this.swProperties.load(this.getClass().getClassLoader().getResourceAsStream(PROP_SW_FILENAME));

	    this.reasoningRules = FileUtils.readFileToString(new File(this.getClass().getClassLoader().getResource(PROP_REASONER_RULES).getFile()));
	}
	catch (IOException e) {
	    e.printStackTrace();
	}

    }

    public String getReasoningRules() {
	return this.reasoningRules;
    }

    public String getDataPath() {
	return this.swProperties.getProperty("data");
    }

    public Properties getTagProperties() {
	return this.tagProperties;
    }

    public static void main(String[] args) {
	ResourceLoader loader = new ResourceLoader();
	System.out.println(loader.getTagProperties());

    }

}
